﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sys_pos_tree.aspx.cs" Inherits="Ccit.SysPlat.Organ.sys_pos_tree" %>
<%@ Register assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="Microsoft.Web.UI.WebControls" tagprefix="iewc" %>

<html>
<head runat="server">
    <title></title>
    <style>
		.skin { BORDER-RIGHT: buttonhighlight 2px outset; BORDER-TOP: buttonhighlight 2px outset; FONT-SIZE: 9pt; VISIBILITY: hidden; BORDER-LEFT: buttonhighlight 2px outset; WIDTH: 100px; CURSOR: default; BORDER-BOTTOM: buttonhighlight 2px outset; FONT-FAMILY: Arial, Helvetica, sans-serif; POSITION: absolute; BACKGROUND-COLOR: menu; TEXT-ALIGN: left }
		.menuitems { PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-TOP: 4px; PADDING-BOTTOM: 4px;}
	</style>
</head>
<body>
    <form id="form1" runat="server">  
    <input type="hidden" id="_hidOrganId" runat="server" /> 
    <input type="hidden" id="_hidAddNewSign" runat="server" /> <!-- 新增记录标志 -->
    <input type="hidden" id="_hidDelPosId" runat="server" />  
    <input type="hidden" id="_hidCurPosExpr" runat="server" /> 
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>
    <div id="root" class="skin" style="LEFT:0px; VISIBILITY:hidden; WIDTH:90px; TOP:0px; HEIGHT:30px">
        <div onclick="clickItem()" onMouseover="highlighItem()" onMouseout="lowlightItem()"  class="menuitems" func="DelPos">            
                <img src="../images/toolbar/delete.gif" border="0" />&nbsp; 删除职位           
        </div>       
    </div>    
    <iewc:TreeView ID="trvPos" runat="server">
    </iewc:TreeView>    
    <input type="button" id="btnTrigger" onclick="doTrigger()" style="display:none" value="触发事件" />
    <input type="button" id="btnDelTrigger" onclick="doDelTrigger()" style="display:none" value="删除触发事件" />
    </form>
    <script type="text/javascript">
    <!--
        var menuskin = "skin";
        var node = null;
        var menuname = "root";

        function hideMenu() {
            var obj = document.getElementById(menuname);
            if (null != obj && typeof (obj) != "undefined")
                document.getElementById(menuname).style.visibility = "hidden";
        }

        function highlighItem() {
            if (event.srcElement.className == "menuitems") {
                event.srcElement.style.backgroundColor = "highlight";
                event.srcElement.style.color = "white";
            }
        }
        function lowlightItem() {
            if (event.srcElement.className == "menuitems") {
                event.srcElement.style.backgroundColor = "";
                event.srcElement.style.color = "black";
                window.status = "";
            }
        }
        function clickItem() {
            if (node != null) {
                var vPosId = node.getAttribute("ID");                				
                var nodeType = node.getAttribute("type").toUpperCase();
                var vOrganId = $get("_hidOrganId").value;

                if (event.srcElement.className == "menuitems" && event.srcElement.disabled != true) {
                    var sFuncName = event.srcElement.getAttribute("func");
                    switch (sFuncName) {
                        case "DelPos": //删除职位					    
                            hideMenu();
                            if (!confirm("删除当前职位,是否继续?")) return;
                            var nodeIndex = node.getNodeIndex();
                            PageMethods.DeletePos(vPosId, nodeIndex, ClientCallBack);

                            break;
                        default:
                            break;
                    }
                }
            }
        }

        function trvPos.oncollapse() {
            hideMenu();
        }

        function trvPos.oncontextmenu() {
            hideMenu();
            var nodeIndex = event.treeNodeIndex;
            if (typeof (nodeIndex) == "undefined") {
                node = null;
                return false;
            }
            trvPos.selectedNodeIndex = nodeIndex;
            node = trvPos.getTreeNode(nodeIndex);
            var vPosId = node.getAttribute("ID");

            if (vPosId == "0") return;  //根节点不显示右键菜单

            var obj = document.getElementById("root");
            if (null == obj || typeof (obj) == "undefined") {
                node = null;
                return false;
            }

            var rightedge = document.body.clientWidth - event.clientX; 	//右边距
            var bottomedge = document.body.clientHeight - event.clientY; //底边距

            if (rightedge < obj.offsetWidth)
                obj.style.left = document.body.scrollLeft + 5 + event.clientX - obj.offsetWidth;
            else
                obj.style.left = document.body.scrollLeft + 5 + event.clientX;

            if (bottomedge < obj.offsetHeight)
                obj.style.top = document.body.scrollTop + 5 + event.clientY - obj.offsetHeight;
            else
                obj.style.top = document.body.scrollTop + 5 + event.clientY;

            obj.style.visibility = "visible";
            return false;
        }

        function ClientCallBack(vResult) {
            if (null == vResult || vResult == "undefined") {
                alert("网络传输错误,没有正确的返回值,请检查网络是否畅通!");
                return;
            }
            eval("var resultObj=" + vResult);
            var operType = resultObj.OPERTYPE;
            switch (operType) {
                case "POSDELETE":  //删除职位
                    var nodeIndex = resultObj.NODEINDEX;
                    alert(resultObj.RSTMSG);
                    if (parseInt(resultObj.RSTSIGN) > 0) {                        
                        var node = $get("trvPos").getTreeNode(nodeIndex);
                        node.remove();
                        parent.frames[1].initAddNew();
                    }                   
                    break;
            }

            resultObj = null;
        }

        function createSubTreeNodes(nodeIndex, subPosArray) {
            var node = $get("trvPos").getTreeNode(nodeIndex);
            var vOrganId = $get("_hidOrganId").value;
            var vPosId;
            var vPosName;            
            var vNavigateUrl;
            var itemCount = subPosArray.length;
            var subPos;
            var vPageParam;
            var encodeParam;

            var newNodeIndex = "";
            for (var i = 0; i < itemCount; i++) {
                subPos = subPosArray[i];
                vPosId = subPos.posId;
                vPosName = subPos.posName;
                vPageParam = "organId=" + vOrganId + "&posId=" + vPosId;
                encodeParm = base64encode(vPageParam);
                vNavigateUrl = "./sys_pos_edit.aspx?" + encodeParm;
                oSubNode = $get("trvPos").createTreeNode();
                oSubNode.setAttribute("ID", vPosId);
                oSubNode.setAttribute("Text", vPosName);
                oSubNode.setAttribute("Type", "root");
                oSubNode.setAttribute("Target", "ifrmEdit");
                oSubNode.setAttribute("ImageUrl", "../images/organ/pos.gif");
                oSubNode.setAttribute("NavigateUrl", vNavigateUrl);
                
                node.add(oSubNode);
            }

            newNodeIndex = oSubNode.getNodeIndex();
            return newNodeIndex; 
        }

        function findTreeNode(findPosId) {
            var ctrlTree = document.getElementById("trvPos");

            var ctrlRoot = ctrlTree.getTreeNode("0");
            var ctrlChildNodes = ctrlRoot.getChildren();

            var ctrlFindNode = recursionFind(ctrlChildNodes, findPosId);
            return ctrlFindNode;

        }

        function recursionFind(ctrlChildNodes, findPosId) {
            var iLen = ctrlChildNodes.length;
            var ctrlTreeNode;            
            var vPosId;
            var ctrlSubChildNodes;
            var bFind = false;

            for (var i = 0; i < iLen; i++) {
                ctrlTreeNode = ctrlChildNodes[i];
                vPosId = ctrlTreeNode.getAttribute("ID");
                if (vPosId == findPosId) {
                    bFind = true;
                    break;
                }
                else {
                    ctrlSubChildNodes = ctrlTreeNode.getChildren();
                    ctrlTreeNode = recursionFind(ctrlSubChildNodes, findPosId);
                    if (null != ctrlTreeNode) {
                        bFind = true;
                        break;
                    }
                }
            }

            if (bFind)
                return ctrlTreeNode;
            else
                return null;
        }

        function doTrigger() {
            var isAddNew = $get("_hidAddNewSign").value;
            eval("var curNodeObj=" + $get("_hidCurPosExpr").value);
            var curNodeIndex = 0;
            if (isAddNew == "1") {//编辑               
                var curNodeId = curNodeObj.posId;
                var curNode = findTreeNode(curNodeId);
                curNode.setAttribute("Text", curNodeObj.posName);
                curNodeIndex = curNode.getNodeIndex();
            }
            else {
                var subPosArray = [];
                subPosArray.push(curNodeObj);
                curNodeIndex = createSubTreeNodes("0", subPosArray);
                subPosArray = null;
            }
            
            
            curNodeObj = null;
            expandRoot();  //展开根节点
            $get("trvPos").selectedNodeIndex = curNodeIndex;
        }
        

        function doDelTrigger() {
            var delPosId = $get("_hidDelPosId").value;
            ctrlNode = findTreeNode(delPosId);
            nodeIndex = ctrlNode.getNodeIndex();
            var node = $get("trvPos").getTreeNode(nodeIndex);
            node.remove();
        }

        function expandRoot() {
            var ctrlRoot = $get("trvPos").getTreeNode("0");
            ctrlRoot.setAttribute("EXPANDED", true);
        }
      
    //-->
    </script>    
</body>
</html>
